package com.ruix.app.mapper;

import android.text.TextUtils;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by hadexs on 2017/7/3.
 */

public class TagsMapper implements ApiMapper<ArrayList<String>>{

    @Override
    public ArrayList<String> transform(JSONObject response) {
        ArrayList tags = null;
        if (response != null){
           JSONObject data =  response.optJSONObject("data");
            if (data != null){
              JSONArray taglist =  data.optJSONArray("list");
                if (taglist != null){
                    tags = new ArrayList();
                    for (int i = 0; i < taglist.length(); i++) {
                       String tag =  taglist.optString(i,"");
                        if (!TextUtils.isEmpty(tag)){
                            tags.add(String.format("#%s#",tag));
                        }
                    }
                }
            }
        }
        return tags;
    }
}
